package entity;

import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Observer;

public class ENode {
	private String name;
	private int nodeID;
	private int objectIndex;
	private int BRAMOffset;
	private HashMap<String,ERegister> registers = new LinkedHashMap<String,ERegister>();
	
	public ENode(String name, int nodeID, int objectIndex, int BRAMOffset) {
		this.name = name;
		this.nodeID = nodeID;
		this.objectIndex = objectIndex;
		this.BRAMOffset = BRAMOffset;
		System.out.print(name + " " + BRAMOffset + "\n");
		
	}
	
	public String getName() {
		return name;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public int getNodeID() {
		return nodeID;
	}
	
	public void setNodeID(int nodeID) {
		this.nodeID = nodeID;
	}
	
	public int getObjectIndex() {
		return objectIndex;
	}
	
	public void setObjectIndex(int objectIndex) {
		this.objectIndex = objectIndex;
	}
	
	public int getBRAMOffset() {
		return BRAMOffset;
	}
	
	public void setName(int BRAMOffset) {
		this.BRAMOffset = BRAMOffset;
	}
	
	public void addRegister(ERegister register) {
		registers.put(register.getName(), register);
	}
	
	public HashMap<String,ERegister> getRegisters() {
		return registers;
	}
	
	public ERegister getRegister(String register) {
		return registers.get(register);
	}
	
	public void addObserver(String register, Observer observer) {
		registers.get(register).addObserver(observer);
	}
	
	public void removeObserver(String register, Observer observer) {
		registers.get(register).deleteObserver(observer);
	}
	
	public String getRegisterName(String startsWith) {
		Iterator<String> registerList = registers.keySet().iterator();
		
		while (registerList.hasNext()) {
			String registerName = registerList.next();
			if (registerName.startsWith(startsWith)) {
				return registerName;
			}
		}
		
		return null;
	}
}
